// PipeReadThread.h: interface for the CPipeReadThread class.
//
//////////////////////////////////////////////////////////////////////
// Pipe read thread
// Luey (LiuYu@LiuYu.com)
// 2008-08-31
//////////////////////////////////////////////////////////////////////////

#pragma once

#if !defined(PIPE_READ_THREAD_H__0A7D5651_D4D3_46fc_B6D9_8A882EDB17BC__INCLUDED)
#define PIPE_READ_THREAD_H__0A7D5651_D4D3_46fc_B6D9_8A882EDB17BC__INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <string>

class CPipeReadThreadListener
{
public:
	virtual void PipeReadThreadStart() = 0;
	virtual void PipeReadThreadReceive(const void * pBuffer, const unsigned long nBufLen) = 0;
	virtual void PipeReadThreadLog(std::wstring wsLog) = 0;
	virtual void PipeReadThreadStop() = 0;
};


class CPipeReadThread
{
public:
	static const int SUCCESS			= (0);
	static const int UNDEFINED_ERROR	= (100);

	static const int MAX_BUFFER_LENGTH	= (1024);

	typedef struct tagPARAMETER
	{
		HANDLE	hThisThread;
		DWORD	dwThisThreadId;

		CPipeReadThreadListener * pListener;

		HANDLE	hPipe;
	}
	FAR * LP_PARAMETER, PARAMETER;

protected:
	CPipeReadThread(void);
	~CPipeReadThread(void);

public:
	static HANDLE StartThread(LP_PARAMETER pParameter, LPDWORD lpThreadId = NULL);
	static DWORD ThreadFunc(LP_PARAMETER lpParameter);
};
#endif // PIPE_READ_THREAD_H__0A7D5651_D4D3_46fc_B6D9_8A882EDB17BC__INCLUDED